// pages/heart_rate/heart_rate.ts
Page({
  /**
   * 页面的初始数据
   */
  data: {
    active: 0,
    title_to_top: 0,
    showCalendar: false,
    recordDate: "",
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad() {
    const rect = wx.getMenuButtonBoundingClientRect();
    this.setData({
      title_to_top: rect.height,
    });
  },

  onClickBack() {
    wx.navigateBack();
  },

  onClickRight() {
    wx.showToast({ title: "右侧按钮点击", icon: "none" });
  },

  onTabChange(event: any) {
    this.setData({ active: event.detail.index });
  },

  onOpenCalendar() {
    this.setData({ showCalendar: true });
  },
  onCloseCalendar() {
    this.setData({ showCalendar: false });
  },
  onConfirmDate(event: any) {
    const date = event.detail;
    // date 是一个时间戳
    const d = new Date(date);
    const recordDate = `${d.getFullYear()}-${(d.getMonth() + 1)
      .toString()
      .padStart(2, "0")}-${d.getDate().toString().padStart(2, "0")}`;
    this.setData({ recordDate, showCalendar: false });
  },
});
